package com.bjc.sdx.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.bjc.sdx.R;
import com.bjc.sdx.service.MyService1;

public class ServiceActivity extends Activity {
    private Button start;
    private Button stop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.service1_layout);

        start = (Button) findViewById(R.id.but_start);
        stop = (Button) findViewById(R.id.but_stop);
        //创建启动Service的Intent,以及Intent属性
        final Intent intent = new Intent(ServiceActivity.this, MyService1.class);
        //为两个按钮设置点击事件,分别是启动与停止service
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startService(intent);
            }
        });

        stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                stopService(intent);
            }
        });
    }

}
